import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import About from '../views/About.vue'
import Resume from '../components/resume.vue'
import store from '../store'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },{
    path: '/about:id',
    name: 'About',
    component: About
   },{
	path: '/edit:id',
	name: 'Resume',
	component: Resume
   }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
	/**
	 * 路由守卫，当简历份数为0时，禁止访问编辑页面
	 * 路由守卫，当简历份数为0时，禁止访问预览页面
	 */
	if ((to.path === '/edit0'&&(store.state.resumes.length==0))||(to.path === '/about0'&&(store.state.resumes.length==0))) {
		  // alert("请先创建一份简历哦")
		  return next('/')
	} else {
	      return next()
	}
})

export default router
